package com.itheima.handler;

import com.itheima.exception.BusinessException;
import com.itheima.vo.Result;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobaExceptionHander {
    @ExceptionHandler(BusinessException.class)
    public  Result hanlerDup(Exception e){
        return  Result.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result hanException(Exception e){
        e.printStackTrace();
        return  Result.error("出错误啦");
    }
}
